package com.googlecode.afx.view.binding;

import java.beans.PropertyDescriptor;
import java.util.Map;

import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeansException;
import org.springframework.beans.InvalidPropertyException;
import org.springframework.beans.PropertyAccessorFactory;
import org.springframework.beans.PropertyValue;
import org.springframework.beans.PropertyValues;
import org.springframework.core.convert.TypeDescriptor;

import jfxtras.labs.scene.control.BeanPathAdapter;

/**
 * An adapter that takes a POJO bean and internally and recursively
 * binds/un-binds it's fields to other {@link Property} components. 
 * <p>
 * Please refer to <tt></tt> for further information.
 * 
 */
@SuppressWarnings("rawtypes")
public class BeanWrapperAdapter extends BeanPathAdapter {

	private BeanWrapper beanWrapper;

	/**
	 * Constructor
	 * 
	 * @param bean
	 *            the bean the {@link BeanWrapperAdapter} is for
	 */
	@SuppressWarnings("unchecked")
	public BeanWrapperAdapter(final Object bean) {
		super(bean);
		this.beanWrapper = PropertyAccessorFactory.forBeanPropertyAccess(bean);
	}

	public boolean isReadableProperty(String propertyName) {
		return beanWrapper.isReadableProperty(propertyName);
	}

	public Object getWrappedInstance() {
		return beanWrapper.getWrappedInstance();
	}

	public boolean isWritableProperty(String propertyName) {
		return beanWrapper.isWritableProperty(propertyName);
	}

	public Class<?> getWrappedClass() {
		return beanWrapper.getWrappedClass();
	}

	public PropertyDescriptor[] getPropertyDescriptors() {
		return beanWrapper.getPropertyDescriptors();
	}

	public Class<?> getPropertyType(String propertyName) throws BeansException {
		return beanWrapper.getPropertyType(propertyName);
	}

	public PropertyDescriptor getPropertyDescriptor(String propertyName) throws InvalidPropertyException {
		return beanWrapper.getPropertyDescriptor(propertyName);
	}

	public TypeDescriptor getPropertyTypeDescriptor(String propertyName) throws BeansException {
		return beanWrapper.getPropertyTypeDescriptor(propertyName);
	}

	public Object getPropertyValue(String propertyName) throws BeansException {
		return beanWrapper.getPropertyValue(propertyName);
	}

	public void setPropertyValue(String propertyName, Object value) throws BeansException {
		beanWrapper.setPropertyValue(propertyName, value);
	}

	public void setPropertyValue(PropertyValue pv) throws BeansException {
		beanWrapper.setPropertyValue(pv);
	}

	public void setPropertyValues(Map<?, ?> map) throws BeansException {
		beanWrapper.setPropertyValues(map);
	}

	public void setPropertyValues(PropertyValues pvs) throws BeansException {
		beanWrapper.setPropertyValues(pvs);
	}

	public void setPropertyValues(PropertyValues pvs, boolean ignoreUnknown) throws BeansException {
		beanWrapper.setPropertyValues(pvs, ignoreUnknown);
	}

	public void setPropertyValues(PropertyValues pvs, boolean ignoreUnknown, boolean ignoreInvalid)
			throws BeansException {
		beanWrapper.setPropertyValues(pvs, ignoreUnknown, ignoreInvalid);
	}
	
	
}